<?php
declare (strict_types = 1);

namespace app\manage\controller;

use app\admin\model\AdminMenusModel;
use org\Tree;
use think\facade\Request;

class Index extends Basemanage
{
    public function index(){

        return $this->fetch();
    }
    public function main(){

        return $this->fetch();
    }
    public function getSystemInit(){
        $homeInfo = [
            'title' => '控制台',
            'href'  => 'manage/index/main.html',
        ];
        $logoInfo = [
            'title' => 'NoviceAdmin',
            'image' => 'static/images/logo.png',
        ];
        $menuInfo =$this->getMenuList();
        $systemInit = [
            'homeInfo' => $homeInfo,
            'logoInfo' => $logoInfo,
            'menuInfo' => $menuInfo,
        ];
        return json($systemInit);
    }
    public function getMenuList(){
        /**
         * @throws \think\db\exception\DataNotFoundException
         * @throws \think\db\exception\DbException
         * @throws \think\db\exception\ModelNotFoundException
         * @author: LuckyHhy <jackhhy520@qq.com>
         * @date: 2020/6/27 0027
         * @describe:菜单列表
         */
//        if (self::$admin_info['id'] !=1){
//            $data=AdminMenusModel::where("id","in",session("admin_rules"))->where("type","1")->where("status",1)->select()->toArray();
//            if (!empty($data)){
//                foreach ($data as $k => $v) {
//                    if (!empty($v['name'])) {
//                        $data[$k]['url'] = (string)url($v['name']);
//                    }
//                }
//            }
//        }else{
            //超级管理员拥有所有权限
            $data = AdminMenusModel::menuList();
//            exit(json_encode(Tree::DeepTree($data,'sub')));
//        }
           return empty($data) ? []:Tree::DeepTree($data,'child');
    }
}
